<!DOCTYPE html>
<html>


<!-- Mirrored from www.zi-han.net/theme/hplus/login.html by HTTrack Website Copier/3.x [XR&CO'2014], Wed, 20 Jan 2016 14:18:23 GMT -->
<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>demo</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link href="css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">



    <link href="css/style.min862f.css?v=4.1.0" rel="stylesheet">
    <!--[if lt IE 9]>
    <meta http-equiv="refresh" content="0;ie.html" />
    <![endif]-->
    <script>if(window.top !== window.self){ window.top.location = window.location;}</script>
</head>

<body class="gray-bg">

<div class="middle-box text-center loginscreen animated fadeInDown">
    <div>
        <div>

            <h1 class="logo-name">AT</h1>

        </div>
        <h3>聊天室demo</h3>

        <form class="m-t" role="form" id="formL" action="">
            <div class="form-group">
                <input  class="form-control" placeholder="用户名" name="UserName" required="">
            </div>
            <div class="form-group">
                <input type="password" class="form-control" name="Password" placeholder="密码" required="">
            </div>
            <button type="button" id="login" class="btn btn-primary block full-width m-b">登 录</button>


            <p class="text-muted text-center"><a href="register.html">注册一个新账号</a>
            </p>

        </form>
    </div>
</div>
<script src="js/jquery.min.js?v=2.1.4"></script>
<script src="js/bootstrap.min.js?v=3.3.6"></script>

<script type="text/javascript">
    $(document).ready(function()
    {
        $('#login').click(function(e)
        {
            var formObject = {};
            var array = $("#formL").serializeArray();
            $.each(array,function(i,item){
                formObject[item.name] = item.value;
            })
            login(JSON.stringify(formObject) )

        });
    });
    function login(jsonData) {
        $.ajax({
            // 几个参数需要注意一下
            type: "POST",// 方法类型
            dataType: "json",// 预期服务器返回的数据类型
            url: "http://localhost:8080/v1/user/login",//url
            data:   jsonData,
            success: function (result) {

                if (result.code === 0) {
                    setCookie("auth", result.data.Auth)
                    window.location.href = "http://localhost:1999/";
                }else {
                    alert(result.msg)
                }
            },
            error : function() {
                alert("异常！");
            }
        });
    }


    function getCookie(name)
    {
        return localStorage.getItem(name);
    }

    function setCookie(name,value)
    {
        localStorage.setItem(name, value)
    }

</script>

</body>

</html>
